package cn.com.dycc.common.http;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;

import javax.servlet.ServletRequest;

public class HttpHelper {
	
	
	public static String getBodyString(ServletRequest request){
		StringBuilder sb=new StringBuilder();
		InputStream inputStream=null;
		BufferedReader reader=null;
		try {
			inputStream=request.getInputStream();
			reader=new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8")));
			String line="";
			while ((line=reader.readLine())!=null) {
				sb.append(line);
				
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			if(inputStream!=null){
				try {
					inputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if(reader!=null){
				try {
					reader.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return sb.toString();
	}

}
